﻿#region << 版 本 注 释 >>
/*
 * ========================================================================
 * Copyright(c) 北京天大天科科技发展有限公司, All Rights Reserved.
 * ========================================================================
 *  
 * 【当前类文件的功能】
 *  
 * CLR版本：4.0.30319.34014
 * 作者：杨朋飞  时间：2015/4/19 10:13:40
 * 文件名：IniHelper_TDTk
 * 版本：V1.0.0
 * 
 * 修改者：           时间：               
 * 修改说明：
 * ========================================================================
*/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace YPF_CommonMethod
{

    /// <summary>
    /// ini文件操作类_TDTk
    /// </summary>
    public class IniHelper_TDTk
    {
        #region API定义

        //用来写入ini文件的win32API
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string strSection, string strKey, string strValue,
            string strFilePath);

        //用来读取INI 文件的内容
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string strSection, string strKey, string strDefault,
            StringBuilder retrunValue, int iSize, string strFilePath);

        #endregion


        /// <summary>
        /// 读出Setting.ini文件
        /// </summary>
        /// <param name="Section">项目名称(如 [TypeName] )</param>
        /// <param name="Key">键</param>
        public static string ReadValue(string strSection, string strKey)
        {
            StringBuilder temp = new StringBuilder(500);
            int i = GetPrivateProfileString(strSection, strKey, "", temp, 500,
                System.Windows.Forms.Application.StartupPath + "\\Setting.ini");
            return temp.ToString();
        }

        /// <summary>
        /// 写入etting.ini文件
        /// </summary>
        /// <param name="Section">项目名称(如 [TypeName] )</param>
        /// <param name="Key">键</param>
        /// <param name="Value">值</param>
        public static void SaveValue(string strSection, string strKey, string strValue)
        {
            WritePrivateProfileString(strSection, strKey, strValue,
                System.Windows.Forms.Application.StartupPath + "\\Setting.ini");
        }
    }
}
